package com.nondo.dean.auth.controller.api;

import com.nondo.dean.auth.common.bean.CompanyItem;
import com.nondo.dean.auth.common.bean.CompanyTree;
import com.nondo.dean.auth.domain.Company;
import com.nondo.dean.auth.provider.CompanyManager;
import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.Page;
import com.nondo.dean.common.web.Query;
import com.nondo.dean.common.web.View;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * project：dean-cloud
 * 公司對外接口
 *
 * @author linfeng @ nondo
 * @date 2018/4/23
 */
@RestController
@RequestMapping("/{v}/company")
public class CompanyController {

    @Autowired
    private CompanyManager positionManager;


    /**
     * 请求保存部门
     *
     * @param item 部门信息
     * @return 信息提示
     */
    @ApiVersion(1)
    @RequestMapping(
            value = "/save",
            method = RequestMethod.POST
    )
    public View<String> requestSave(@Validated @RequestBody CompanyItem item) {

        return positionManager.requestSave(item);
    }

    /**
     * 请求删除部门
     *
     * @param companyId 部门ID
     * @return 信息提示
     */
    @ApiVersion(1)
    @RequestMapping(
            value = "/delete/{companyId}",
            method = RequestMethod.POST
    )
    public View<String> requestDelete(@PathVariable Long companyId) {

        return positionManager.requestDelete(companyId);
    }

    /**
     * 请求删除部门
     *
     * @param companyIds 部门ID数组
     * @return 信息提示
     */
    @ApiVersion(1)
    @RequestMapping(
            value = "/multi/delete",
            method = RequestMethod.POST
    )
    public View<String> requestMultiDelete(@RequestBody Long[] companyIds) {

        return positionManager.requestMultiDelete(companyIds);
    }

    /**
     * 请求查询部门
     *
     * @param item 部门信息
     * @return 信息提示
     */
    @ApiVersion(1)
    @RequestMapping(
            value = "/list",
            method = RequestMethod.POST
    )
    public View<Page<Company>> requestQuery(@RequestBody Query<CompanyItem> item) {

        return positionManager.requestQuery(item);
    }

    /**
     * 公司树
     *
     * @return 公司树
     */
    @ApiVersion(1)
    @RequestMapping(
            value = {"/tree/all"},
            method = RequestMethod.POST
    )
    public View<List<CompanyTree>> requestCompanyTreeOfAll() {

        return positionManager.requestCompanyTreeOfAll();
    }

    /**
     * 请求删除部门
     *
     * @param companyId 部门ID
     * @return 信息提示
     */
    @ApiVersion(1)
    @RequestMapping(
            value = "/one/{companyId}",
            method = RequestMethod.POST
    )
    public View<Company> requestFindOne(@PathVariable Long companyId) {

        return positionManager.requestQueryOne(companyId);
    }
}
